package com.my.geojson.test.wfs.config;

import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;


@Configuration
public class RetryConfig {

    @Bean
    public Retryer<Boolean> instance(){
        Retryer<Boolean> retryer = RetryerBuilder.<Boolean>newBuilder()
                //返回false也需要重试
                .retryIfResult(Predicates.equalTo(false))
                //抛出runtime异常,checked异常时都会重试,但是抛出error不会重试
                .retryIfException()
                //重试策略
                .withWaitStrategy(WaitStrategies.fixedWait(10, TimeUnit.SECONDS))
                //尝试次数
                .withStopStrategy(StopStrategies.stopAfterAttempt(3))
                .build();
        return retryer;
    }
}
